<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/mainTemplate.xhtml">

    <ui:define name="content">
        <h:form id="customersPage" >
            <p:toolbar id="customersToolbar" style="margin-top:20px; margin-bottom:5px">
                <p:toolbarGroup align="left">
                    <p:commandButton value="Добавить"
                                     action="#{customerBean.addCustomer()}" style="font-size: 85% !important"/>
                    <p:commandButton value="Редактировать"
                                     action="#{customerBean.editCustomer()}" style="font-size: 85% !important"/>
                    <p:commandButton value="Просмотреть"
                                     action="#{customerBean.viewCustomer()}" style="font-size: 85% !important"/>
                </p:toolbarGroup>
            </p:toolbar>

            <p:dataTable id="customersTable" var="customer" value="#{customerBean.customerList}"
                         rowKey="#{customer.name}" selection="#{customerBean.selectedCustomer}"
                         selectionMode="single">

                <p:column headerText="Название">
                    <h:outputText value="#{customer.name}" />
                </p:column>

                <p:column headerText="Полное название">
                    <h:outputText value="#{customer.fullName}" />
                </p:column>

                <p:column headerText="Адрес">
                    <h:outputText value="#{customer.address}" />
                </p:column>

                <p:column headerText="Описание">
                    <h:outputText value="#{customer.description}" />
                </p:column>

            </p:dataTable>
        </h:form>
        <h:form id="addCustomerForm">
            <p:dialog id="addCustomerDialog" widgetVar="addCustomerDialog" header="Добавление заказчика" modal="true">
                <ui:include src="dialogs/addCustomer.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleCreateCustomerRequest(xhr, status, args) {
                    if(args.validationFailed || !args.saveCustomer) {
                        jQuery('#addCustomerDialog').effect("shake", { times:3 }, 100);
                    } else {
                        addCustomerDialog.hide();
                    }
                }
            </script>
        </h:form>
        <h:form id="editCustomerForm">
            <p:dialog id="editCustomerDialog" widgetVar="editCustomerDialog" header="Изменение заказчика" modal="true">
                <ui:include src="dialogs/editCustomer.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleEditCustomerRequest(xhr, status, args) {
                    if(args.validationFailed || !args.editCustomer) {
                        jQuery('#editCustomerDialog').effect("shake", { times:3 }, 100);
                    } else {
                        editCustomerDialog.hide();
                    }
                }
            </script>
        </h:form>
    </ui:define>
</ui:composition>